Skip to content

Randomize a List in C#: .NET 11, built-in shuffles and a fixed benchmark - #2389

Merged
vladimir-pecanac-main merged 3 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/79992-csharp-randomize-list
Nov 22, 2026
Merged

vladimir-pecanac-main merged 3 commits into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/79992-csharp-randomize-list

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Moves collections-lists/RandomizeGenericListsInCSharp from net7.0 to net11.0 (BenchmarkDotNet 0.15.8, MSTest 4.5.3, Microsoft.NET.Test.Sdk 18.12.0, coverlet.collector 10.1.0), adds Random.Shuffle over CollectionsMarshal.AsSpan, LINQ Shuffle, a labelled biased loop and a CountOrders helper that Program.cs uses to print a fairness count when run without arguments, moves the benchmark into its own in-process class where the two in-place shuffles get a fresh ordered copy per iteration, and rewrites the tests so they check that each shuffle returns a permutation of the input in a new order.

…and fix the benchmark

Target net11.0 with BenchmarkDotNet 0.15.8 and MSTest 4.5.3. Add Random.Shuffle,
LINQ Shuffle, a biased loop for the fairness count and CountOrders. Move the
benchmark to its own in-process class that gives the in-place methods a fresh
ordered copy per iteration. Tests now check the result is a permutation of the input.
@vladimir-pecanac-main
vladimir-pecanac-main merged commit 44f1918 into CodeMazeBlog:main Nov 22, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant